﻿@model PcaWeb.Models.LogOnModel

@{
    ViewBag.Title = "Login";
    var X = Html.X();
}

@section Head
{
    <script type="text/javascript">

        //Siempre Top location
        if (window.top.frames.length !== 0) {
            window.top.location = self.document.location;
        };

        //Funcion para validar Login
        var fnValidateForm = function () {
            var form = this.up('window').down('form');

            if (form.getForm().isValid()) {
                Ext.Msg.wait('Autentificando...', 'Login');
            }
            else {
                return false;
            }
        };

    </script>
}

@(
 X.Window()
        .ID("winLoginEmpresa")
        .Closable(false)
        .CloseAction(CloseAction.Destroy)
        .Resizable(false)
        .Icon(Icon.Lock)
        .Title("Login")
        .Layout(LayoutType.Fit)
        .Width(350)
        .Modal(false)
        .BodyPadding(5)
        .Constrain(true)
        .Items(
            X.FormPanel()
                .Layout(LayoutType.Form)
                .Border(false)
                .BodyStyle("background-color:transparent;")
                .FieldDefaults(fieldDefaults => { fieldDefaults.LabelWidth = 120; })
                .Items(
                    X.TextFieldFor(x => x.UserName),
                    X.TextFieldFor(x => x.Password).EnableKeyEvents(true).Listeners(l => { l.KeyPress.Handler = "if (e.getKey() == e.ENTER) {#{btnSumit}.fireEvent('click');}"; }),
                    X.Hidden().ID("ReturnUrl").Value(ViewData["returnUrl"])
                )
        )
        .Buttons(
            X.Button()
                .ID("btnSumit")
                .Text("Login")
                .Icon(Icon.Accept)
                .DirectEvents(de =>
                {
                    de.Click.Url = Url.Action("ConsultarOficinas");
                    de.Click.Timeout = 60000;
                    de.Click.FormID = "#(return this.up('window').down('form');)";
                    de.Click.CleanRequest = true;
                    de.Click.Method = HttpMethod.POST;
                    de.Click.Before = "fnValidateForm";
                    de.Click.Success = "App.winLoginEmpresa.close();";
                    de.Click.Failure = "Ext.Msg.show({title:'Login Error', msg: result.msg, buttons: Ext.Msg.OK,icon: Ext.MessageBox.ERROR });";
                    de.Click.EventMask.MinDelay = 250;
                }))
)